var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		datalist: [],
		content_pic:[],
		pagenum: 1,
		cindex:-1,
        video:'',
        selectIds:[],
        cid:0
	},
	_onLoad:function(){
		var that = this
		$.get('yuxun/fatiedyq',{},function(res){
			if(res.status == 0){
				$.alert(res.msg);
				return ;
			}
			that.setData(res)
		})
	},
	cateChange:function(e){
		this.setData({cindex:e.detail.value})
    },
    changeTagType2:function(e){
        var  id = e.currentTarget.dataset.id;
        var cid = this.data.cid;
       
        var idx = e.currentTarget.dataset.index;
        let clist = [...this.data.clist];

       for(var i=0;i<clist.length;i++){
        clist[i].select=false;
           if(id==clist[i].id){
               clist[i].select=true
           }
       }
        
        this.setData({clist:clist,cid:id})
    },
	formsubmit:function(e){
		var that = this

		var formdata = e.detail.value
		var content = formdata.content
		var pics = formdata.pics
		//var video = formdata.video
		if(content=='' && pics==''){
			$.error('请输入内容');return false;
        }
        var cid = this.data.cid;
        if(cid==0){
            $.error('请选择分类');return false;
        }


		$.post('yuxun/fatiedyq',{pics:pics,content:content,cid:cid},function(res){
			$.loading(false);
			if(res.status==1){
				$.success(res.msg);
				setTimeout(function(){
					var pages = getCurrentPages();
					if (pages.length > 1) {
						var prePage = pages[pages.length - 2];
						prePage._onLoad();
					}
					$.goback();
				},1000)
			}else{
				$.error(res.msg)	
			}
    })
  
  },
    // 接入安全接口
    /**
 * 珊瑚图片内容安全
 */
doImgSecCheck(e) {
  var d = Date.now()
  wx.serviceMarket.invokeService({
    service: 'wxee446d7507c68b11',
    api: 'imgSecCheck',
    data: {
      "Action": "ImageModeration",
      "Scenes": ["PORN", "POLITICS", "TERRORISM", "TEXT"],
      // "ImageUrl": "http://mat1.gtimg.com/pingjs/ext2020/qqindex2018/dist/img/qq_logo_2x.png",
      "ImageUrl": e,
      "ImageBase64": "",
      "Config": "",
      "Extra": ""
    },
  }).then(res => {
    console.log(res)
  })
},
//doImgSecCheck()
 
/**
 * 珊瑚文本内容安全
 */
//  ddoMsgSecCheck(e){
//   wx.serviceMarket.invokeService({
//     service: 'wxee446d7507c68b11',
//     api: 'msgSecCheck',
//     data: {
//       "Action": "TextApproval",
//       // "Text": "hello world!"
//       "Text": e
//     },
//   }).then(res => {
//     console.log(res)
//   })
// },





	uploadvideo:function(){
		var that = this
		console.log(11)
		wx.chooseVideo({
			sourceType: ['album', 'camera'],
			maxDuration: 60,
			success: function (res){
				var tempFilePath = res.tempFilePath;
				$.loading('上传中');
				wx.uploadFile({
					url: $.config.baseurl + 'Imageupload/uploadImg/aid/'+$.aid+'/platform/'+$.platform+'/session_id/' + $.config.session_id,
					filePath: tempFilePath,
					name: 'file',
					success: function (res) {
						$.loading(false);
						var data = JSON.parse(res.data);
						if(data.status == 1){
							that.setData({video:data.url});
						} else {
							$.alert(data.msg);
						}
					},
					fail: function (res) {
						$.loading(false);
						$.alert(res.errMsg);
					}
				});
			},
			fail: function (res) {
				console.log(res)
				//alert(res.errMsg);
			}
		})
	}
}))